package com.example.bookmanagementsystem.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@Aspect
public class TimeAspect {

    @Around("execution(* com.example.bookmanagementsystem.controller.*.*(..))")
    public Object timeCostCalculate(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        long startTime = System.currentTimeMillis();
        //方法执行前逻辑
        log.info("方法执行前");
        //执行目标方法
        Object result = proceedingJoinPoint.proceed();
        long endTime = System.currentTimeMillis();
        //方法执行后逻辑
        log.info("方法执行后");
        log.info(proceedingJoinPoint + "消耗时间: " + (endTime - startTime) + "ms");
        return result;
    }
}
